<template>
	<view>
		<!-- 地址 -->
		<view  class="address-section" @click="goAddress">
			<view class="order-content" v-if="addressDefault">
				<text class="yticon icon-shouhuodizhi"></text>
				<view class="cen">
					<view class="top">
						<text class="name">{{addressDefault.name}}</text>
						<text class="mobile">{{addressDefault.phoneNumber}}</text>
						<text class="tag" v-if="addressDefault.defaultStatus==1">默认</text>
					</view>
					<view class="address">
						<text class="mobile">{{addressDefault.idCard}}</text>
					</view>
					<text class="address">{{addressDefault.province}} {{addressDefault.city}} {{addressDefault.region}} {{addressDefault.detailAddress}}</text>
				</view>
				<text class="yticon icon-you" v-if="orderStatus=='create'"></text>
			</view>
            <view class="order-content isNo" v-else>
                <view class="cen">
                    <view class="top">
                        <text class="name">还没有地址哦，点击添加地址</text>
                    </view>
                </view>
                <text class="yticon icon-you"></text>
            </view>
        </view>

		<view class="goods-section" v-for="(item,index) in detailList" :key="index" v-if="!dataString">
			<!-- 商品列表 -->
			<view class="g-item" v-for="(cItem,cIndex) in item.omsCartItems">
				<view class="panic" v-if="cItem.flashEndTime && bStatus == 'panic'">
					<text class="tag" v-if="cItem.flashStatus=='start'">限时抢购中</text>
					<text class="tag" v-if="cItem.flashStatus=='end'">限时已结束</text>
					<text class="" v-if="cItem.flashStatus=='start'">距离优惠结束</text>
					<text class="" v-if="cItem.flashStatus=='start'">{{cItem.coutDownDie.a}}</text>
				</view>
				<image :src="cItem.productPic"></image>
				<view class="right">
					<view class="title clamp">
                        <view class="t-name" >{{cItem.productName}}</view>
                        <text class="price" v-if="bStatus=='integral'">{{cItem.integralNum}}积分</text>
                        <text class="price" v-else>￥{{cItem.price}}</text>
                    </view>
					<view class="price-box">
                        <view><img :src="cItem.nationalFlag" alt=""><text>{{cItem.originCountry}}</text></view>
						<text class="number">x {{buyNum}}</text>
					</view>
                    <text class="spec">规格：{{cItem.productAttr}}</text>
					<view class="refund" v-if="orderStatus=='pending'"><text>退款</text></view>
					<view class="refund" v-if="orderStatus=='comment'"><text>申请售后</text></view>
				</view>
			</view>
		</view>

        <!--购物传商品传入,订单传入处理-->
        <view class="goods-section" v-for="(item,index) in detailList" :key="index" v-if="dataString && item.omsCartItems.length!==0">
            <view class="g-header b-b">
                <text class="name">{{item.wareHouseName}}</text>
                <text class="g-status" v-if="orderStatus=='detailPay'">待付款</text>
                <text class="g-status" v-if="orderStatus=='pending'">已发货</text>
                <text class="g-status" v-if="orderStatus=='comment'">待评价</text>
				<text class="g-status" v-if="orderStatus=='refund'">已退款</text>
				<text class="g-status ok" v-if="orderStatus=='finish'">交易完成</text>
            </view>
            <!-- 商品列表 -->
            <view class="g-item" v-for="(cItem,cIndex) in item.omsCartItems" v-if="cItem.checked||item.orderItemList">
                <view class="panic" v-if="cItem.flashEndTime && bStatus == 'panic'">
                    <text class="tag" v-if="cItem.flashStatus=='start'">限时抢购中</text>
                    <text class="tag" v-if="cItem.flashStatus=='end'">限时已结束</text>
                    <text class="" v-if="cItem.flashStatus=='start'">距离优惠结束</text>
                    <text class="" v-if="cItem.flashStatus=='start'">{{cItem.coutDownDie.a}}</text>
                </view>
                <image :src="cItem.productPic"></image>
                <view class="right">
                    <view class="title clamp"><view class="t-name" >{{cItem.productName}}</view><text class="price">￥{{cItem.price}}</text></view>
                    <view class="price-box">
                        <view><img :src="cItem.nationalFlag" alt=""><text>{{cItem.originCountry}}</text></view>
                        <text class="number">x {{cItem.quantity}}</text>
                    </view>
                    <text class="spec">规格：{{cItem.productAttr}}</text>
                    <view class="refund" v-if="orderStatus=='pending'&&!cItem.refundStatus" @click="goRefund(item.id,cItem)"><text>退款</text></view>
                    <view class="refund" v-if="orderStatus=='pending'&&cItem.refundStatus=='1'" @click="goRefundDetail(item.id,cItem.productId,cItem.productSkuId)"><text>退款中</text></view>
                    <view class="refund" v-if="(orderStatus=='pending' || orderStatus=='comment')&&cItem.refundStatus=='2'" ><text>已退款</text></view>
                    <view class="refund" v-if="orderStatus=='comment'&&!cItem.refundStatus"><button open-type="contact" session-from=""><text>申请售后</text></button></view>
                </view>
            </view>
        </view>

		<!-- 优惠明细 -->
		<!--<view class="yt-list">-->
			<!--<view class="yt-list-cell b-b" @click="toggleMask('show')">-->
				<!--<view class="cell-icon">-->
					<!--券-->
				<!--</view>-->
				<!--<text class="cell-tit clamp">优惠券</text>-->
				<!--<text class="cell-tip active">-->
					<!--选择优惠券-->
				<!--</text>-->
				<!--<text class="cell-more wanjia wanjia-gengduo-d"></text>-->
			<!--</view>-->
			<!--<view class="yt-list-cell b-b">-->
				<!--<view class="cell-icon hb">-->
					<!--减-->
				<!--</view>-->
				<!--<text class="cell-tit clamp">商家促销</text>-->
				<!--<text class="cell-tip disabled">暂无可用优惠</text>-->
			<!--</view>-->
		<!--</view>-->
		<!-- 金额明细 -->
		<view class="yt-list">
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">商品合计</text>
                <text class="cell-tip" v-if="bStatus=='integral'&&!dataString">{{(detailList[0].omsCartItems[0].integralNum) * buyNum}}积分</text>
                <text class="cell-tip" v-else-if="bStatus=='integral'&&dataString">{{dataSobj.buyTotal?dataSobj.buyTotal:''}}积分</text>
                <text class="cell-tip" v-else-if="!dataString">￥{{(detailList[0].omsCartItems[0].price) * buyNum}}</text>
                <text class="cell-tip" v-else>￥{{dataSobj.buyTotal?dataSobj.buyTotal:''}}</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">优惠活动</text>
                <text class="cell-tip" v-if="!useCouponObj.id">无优惠</text>
                <text class="cell-tip" v-else>-{{useCouponObj.coupon.amount}}</text>
			</view>
            <view class="yt-list-cell b-b" @click="toggleMask('show')" v-if="couponList.length>0">
                <text class="cell-tit clamp">优惠券</text>
                <text class="cell-tip" v-if="!useCouponObj.id">有{{couponList.length}}张优惠卷可用<text v-if="orderStatus=='create'" class="yticon icon-you"></text></text>
                <text class="cell-tip" v-else>{{useCouponObj.coupon.name}}<text v-if="orderStatus=='create'" class="yticon icon-you"></text></text>
            </view>
			<view class="yt-list-cell b-b"  v-if="couponList.length==0">
				<text class="cell-tit clamp">优惠券</text>
				<text class="cell-tip">无适用优惠券</text>
			</view>
			<view class="yt-list-cell b-b">
				<text class="cell-tit clamp">运费</text>
				<text class="cell-tip">{{LSTS}}</text>
			</view>
            <view class="yt-list-cell b-b">
				<text class="cell-tit clamp">税费</text>
				<text class="cell-tip">已含税</text>
			</view>
			<view class="yt-list-cell actually"
				  v-if="orderStatus=='detailPay'||orderStatus=='pending'||orderStatus=='comment'">
				<text class="cell-tit clamp">实付</text>
                <!--<text class="cell-tip m" v-if="bStatus=='integral'&&!dataString">{{(detailList[0].omsCartItems[0].integralNum) * buyNum}}积分</text>-->
                <text class="cell-tip m" v-if="bStatus=='integral'&&dataString">{{dataSobj.buyTotal?dataSobj.buyTotal:''}}积分</text>
				<text class="cell-tip m" v-else>￥{{dataSobj.buyTotalTrue?dataSobj.buyTotalTrue:''}}</text>
			</view>
		</view>
		<!--订单明细-->
		<view class="yt-list">
			<view class="yt-list-cell b-b"
				  v-if="orderStatus=='detailPay'||orderStatus=='pending'||orderStatus=='comment'"
			>
				<text class="cell-tit clamp">订单编号</text>
				<text class="cell-tip">{{dataString.orderSn}}</text>
			</view>
			<view class="yt-list-cell b-b" v-if="orderStatus=='pending'||orderStatus=='comment'">
				<text class="cell-tit clamp">支付方式</text>
				<text class="cell-tip">微信</text>
			</view>
			<view class="yt-list-cell b-b" v-if="orderStatus=='pending'||orderStatus=='comment'">
				<text class="cell-tit clamp">支付编号</text>
				<text class="cell-tip">{{dataString.trxid?dataString.trxid:''}}</text>
			</view>
			<view class="yt-list-cell b-b"
				  v-if="orderStatus=='detailPay'||orderStatus=='pending'||orderStatus=='comment'"
			>
				<text class="cell-tit clamp">下单时间</text>
				<text class="cell-tip">{{dataString.createTime}}</text>
			</view>
			<view class="yt-list-cell b-b"
				  v-if="orderStatus=='comment'"
			>
				<text class="cell-tit clamp">成交时间</text>
				<text class="cell-tip">{{dataString.paymentTime}}</text>
			</view>
		</view>
		
		<!-- 底部 创建-->
		<view class="footer" v-if="orderStatus=='create'">
			<view class="price-content">
				<text class="price">实付：</text>
				<text class="price" v-if="bStatus=='integral'&&!dataString">{{(detailList[0].omsCartItems[0].integralNum) * buyNum}}积分</text>
				<text class="price" v-else-if="bStatus=='integral'&&dataString">{{(detailList[0].omsCartItems[0].integralNum) * buyNum}}积分</text>
				<text class="price" v-else-if="!dataString"><text class="price-tip">￥</text>
					{{((detailList[0].omsCartItems[0].price) * buyNum
					- useCouponObj.coupon.amount
					+parseInt(LSTS=="免运费"?0:LSTS)
					).toFixed(2)}}</text>
                <view class="total" v-if="!dataString">共{{buyNum}}件商品</view>
                <!--购物车传入-->
                <text class="price" v-if="dataString">{{(dataSobj.buyTotal - useCouponObj.coupon.amount + parseInt(LSTS==="免运费"?0:LSTS)).toFixed(2)}}</text>
                <view class="total" v-if="dataString">共{{dataSobj.buyNum}}件商品</view>
			</view>
			<text class="submit" @click="submit('create')">提交订单</text>
		</view>
		<!--详情付款-->
		<view class="footer detail" v-if="orderStatus=='detailPay'">
			<text class="submit cancel" @click="submit('cancelBuy')">取消订单</text>
			<text class="submit pay" @click="submit('pay')">付款</text>
		</view>
		<!--确认收货-->
		<view class="footer detail" v-if="orderStatus=='pending'">
			<text class="submit cancel" @click="submit('wuliu')">查看物流</text>
			<text class="submit pay" @click="conifrmPro(dataString.id)">确认收货</text>
		</view>
		<!--评价-->
		<view class="footer detail" v-if="orderStatus=='comment'">
			<text class="submit cancel" @click="submit('wuliu')">查看物流</text>
			<text class="submit pay" @click="submit('appraise')">评价</text>
		</view>
		
		<!-- 优惠券面板 -->
		<view class="mask" :class="maskState===0 ? 'none' : maskState===1 ? 'show' : ''" @click="toggleMask">
			<view class="mask-content" @click.stop.prevent="stopPrevent">
				<!-- 优惠券页面，仿mt -->
				<view class="coupon-item" v-for="(item,index) in couponList" :key="index" @click="useCoupon(item)">
					<view class="con">
						<view class="left">
							<text class="title" v-if="item.coupon.type == 0">满{{item.coupon.minPoint}}元减{{item.coupon.amount}}元 {{item.coupon.name}}</text>
							<text class="title" v-if="item.coupon.type == 1">折扣上限{{item.coupon.discountCeiling}}元 {{item.coupon.name}}</text>
							<text class="title" v-if="item.coupon.type == 2">立减{{item.coupon.amount}}元 {{item.coupon.name}}</text>
							<text class="time">有效期至{{item.endTime}}</text>
						</view>
						<view class="right" v-if="item.coupon.type==0">
							<text class="price">{{item.coupon.amount}}</text>
							<text>{{item.coupon.minPoint}}</text>
						</view>
						
						<view class="circle l"></view>
						<view class="circle r"></view>
					</view>
					<text class="tips">{{item.coupon.name}}</text>
				</view>
				<view class="coupon-item" @click="useCoupon('no')">
					<view class="other">不使用优惠</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
    import {_productDetail} from '../../common/vmeitime-http/home.js'
    import {_defaultAddress} from '../../common/vmeitime-http/address.js'
    import {_buyThis,_buyCart} from '../../common/vmeitime-http/cart.js'
    import {_userCoupon} from '../../common/vmeitime-http/mem.js'
    import {_orderDetail,_confirmPro} from '../../common/vmeitime-http/order.js'
    import {_gLogistics} from '../../common/vmeitime-http/logistics.js'
	import util from '../../common/utils/util'
	export default {
		data() {
			return {
				maskState: 0, //优惠券面板显示状态
				desc: '', //备注
				payType: 1, //1微信 2支付宝
				couponList: [],
				addressData: {
					name: '许小星',
					mobile: '13853989563',
					addressName: '金九大道',
					address: '山东省济南市历城区',
					area: '149号',
					default: false,
				},
				orderStatus:"create",
                                /*
                * create:"正常"，
                * detailPay:"订单详情付款"
                * pending:"待收货"
                * comment:"待评价"
                * refund:"已退款"
                * finish:"交易完成"
                * */
                detailList:[],
                specChildList:[],
                specObj:{},
				specId:"",
				buyNum:"",
                addressDefault:null,
				id:"",
                bStatus:"",
                cStatus:"",
                fId:"",
                dataString:null,//购物车过来字符串解析
                dataSobj:{
                    buyNum:0,
                    buyTotal:0,
					buyTotalTrue:0,
                    carIds:""
                },
                LSTS:"免运费",//运费,
//                isHaveRefund:0,//订单是否有退款，0无退款，1有退款,
				useCouponObj:{
                    coupon:{
                        amount:0
                    }
                },//使用的优惠券
                cartIds:null,
				getOrderId: null
			}
		},
		onLoad(options){
			//商品数据
			//let data = JSON.parse(option.data);
			//console.log(data);
			uni.showLoading({
			    title: '请稍后..',
			    mask: true,
			});
            if(options.orderStatus){
                this.orderStatus  = options.orderStatus;
            }
			if(options.data){
			    if(this.orderStatus=="detailPay" || this.orderStatus=="pending" || this.orderStatus=="comment" || this.orderStatus=="refund"|| this.orderStatus=="finish"){
			        /*订单传入*/
					this.dataString = JSON.parse(options.data);
					this.LSTS = this.dataString.freightAmount
				}else{
			        /*购物车传入*/
                    this.dataString = JSON.parse(options.data).goodsData;
                    console.log(this.dataString)
					if(this.orderStatus=="create"){
						uni.setNavigationBarTitle({title:"创建订单"})
					}
				}

            }else{
				if(this.orderStatus=="create"){
					uni.setNavigationBarTitle({title:"创建订单"})
				}
			}

			this.buyNum = options.num;
			this.specId = options.specId;
			this.id = options.id;
            this.bStatus = options.bStatus;
			console.log(this.bStatus,'bStatus')
            this.fId = options.fId;
			this.loadData(options.id,this.specId);
		},
		methods: {
            async loadData(id,sId) {
//                let productDetail = await _productDetail({id:id});
                let para = {
                        skuId:this.specId,
//                    verifyStatus:"",//("积分兑换的标志0，不能，1能")（正常商品不传）
//                    flashRelationId:"",//("限购商品的id")（正常商品不传）
                        count:parseInt(this.buyNum)
                    };
                if(this.bStatus == "panic"){
                    para.flashRelationId = this.id
                }else if(this.bStatus=="integral"){
                    para.verifyStatus = 1
				}
                let pData = null;
                if(this.dataString){
                    if(this.orderStatus=="detailPay" || this.orderStatus=="pending" || this.orderStatus=="comment" || this.orderStatus=="refund" || this.orderStatus=="finish"){
                        /*时间转换-下单时间*/
                        this.dataString.createTime = util.formatDate.format(new Date(this.dataString.createTime),'yyyy-MM-dd hh:mm:ss');
                        /*优惠券情况转换*/
                        if(this.dataString.couponId){
                            this.useCouponObj ={
                                id:this.dataString.couponId,
                                coupon:{
                                    amount:this.dataString.couponAmount,
									name:this.dataString.couponName?this.dataString.couponName:""
                                }
                            }
						};
                        /*时间转换-支付时间*/
						if(this.orderStatus=="pending" || this.orderStatus=="comment" || this.orderStatus=="refund" || this.orderStatus=="finish"){
                            this.dataString.paymentTime = util.formatDate.format(new Date(this.dataString.paymentTime),'yyyy-MM-dd hh:mm:ss');
						}
                        pData = [];
						pData.push(this.dataString);
                        pData.forEach((item=>{
                            item.omsCartItems = item.orderItemList;
                            item.omsCartItems.forEach((cItem=>{
                                cItem.price = cItem.productPrice;
                                cItem.quantity = cItem.productQuantity;
							}))
						}));
                        for(let i=0;i<pData.length;i++){
                            for(let z=0;z<pData[i].omsCartItems.length;z++){
                                    this.dataSobj.buyNum += pData[i].omsCartItems[z].quantity;
                                    if(pData[i].omsCartItems[z].integralStatus==1){
                                        this.bStatus = "integral";
                                        this.dataSobj.buyTotal += (pData[i].omsCartItems[z].quantity)*(pData[i].omsCartItems[z].integral);
                                    }else{
                                        this.dataSobj.buyTotal += (pData[i].omsCartItems[z].quantity)*(pData[i].omsCartItems[z].price);
                                        this.dataSobj.buyTotalTrue += (pData[i].payAmount);
                                    }

                                    // this.dataSobj.carIds += (pData[i].omsCartItems[z].id).toString()+","
                            }
                        }
                        /*监听订单倒计时*/
                        uni.$on('updateCountDownOrder',function(data){
                            for(let i=0;i<pData.length;i++){
                                for(let z=0;z<pData[i].omsCartItems.length;z++){
                                    if(pData[i].omsCartItems[z].id==data.cId){
                                        // this.dataSobj.buyNum += pData[i].omsCartItems[z].quantity;
                                        pData[i].omsCartItems[z].coutDownDie.a = data.updateCountDown
                                    }
                                }
                            };
                        })
                        this.detailList = pData;
					}else{
                        /*购物车传入计算商品总价和数量，记录购物车ID*/
                        pData = this.dataString;
                        for(let i=0;i<pData.length;i++){
                            for(let z=0;z<pData[i].omsCartItems.length;z++){
                                if(pData[i].omsCartItems[z].checked){
                                    // this.dataSobj.buyNum += pData[i].omsCartItems[z].quantity;
                                    this.dataSobj.buyNum += pData[i].omsCartItems[z].quantity;
                                        this.dataSobj.buyTotal += (pData[i].omsCartItems[z].quantity)*(pData[i].omsCartItems[z].price);
                                    this.dataSobj.carIds += (pData[i].omsCartItems[z].id).toString()+","
                                }
                            }
                        };
//                        console.log("购物车");
//                        console.log(this.dataString);
//                        console.log(pData);
                        let couponPara = {
                            type:2,//1 商品详情 2 勾选购物车 3全部购物车的商品
//                            cartId:pData[0].omsCartItems[0].id,//（商品详情传递）
                            cartIds:(this.dataSobj.carIds).substr(0,this.dataSobj.carIds.length - 1)
                        };
                        this.gotCoupon(couponPara);
                        /*监听购物车倒计时*/
                        let _this = this;
                        uni.$on('updateCountDown',function(data){
//                            console.log(data);
                            for(let i=0;i<pData.length;i++){
                                for(let z=0;z<pData[i].omsCartItems.length;z++){
                                    if(pData[i].omsCartItems[z].id==data.cId){
                                        // this.dataSobj.buyNum += pData[i].omsCartItems[z].quantity;
                                        pData[i].omsCartItems[z].coutDownDie.a = data.updateCountDown
                                    }
                                }
                            };
                        });
                        this.detailList = pData
					}
					// uni.hideLoading();
                }else{
                    let tempbuyThis = await _buyThis(para);
                    let buy = tempbuyThis.data;
                     pData = tempbuyThis.data.data;
                     let couponPara = {
                         type:1,//1 商品详情 2 勾选购物车 3全部购物车的商品
                         cartId:pData[0].omsCartItems[0].id,//（商品详情传递）
//                         cartIds:""//("购物车id的字符串拼接")（勾选传递）
					 };
                     this.cartIds = pData[0].omsCartItems[0].id;
                     this.gotCoupon(couponPara);

                    this.detailList = pData;
                    /*监听抢购倒计时*/
                    let _this = this;
                    uni.$on('updateCountDownPanic',function(data){
                        for(let i=0;i<pData.length;i++){
                            for(let z=0;z<pData[i].omsCartItems.length;z++){
//                                if(pData[i].omsCartItems[z].id==data.cId){
                                // this.dataSobj.buyNum += pData[i].omsCartItems[z].quantity;
                                pData[i].omsCartItems[z].flashEndTime = "999999999";
                                if(data.updateCountDown=="00:00:00"){
                                    pData[i].omsCartItems[z].flashStatus = "end";
                                }else{
                                    pData[i].omsCartItems[z].flashStatus = "start";
                                }
                                pData[i].omsCartItems[z].coutDownDie = {
                                    a:data.updateCountDown
                                };
                                _this.detailList = JSON.parse(JSON.stringify(pData));
//                                }
                            }
                        };
                    })
                    // uni.hideLoading();
                }

                /*根据传入订单状态判断地址选择*/
                if(this.orderStatus=="create"){
                    let defaultAddress = await _defaultAddress();
					if(defaultAddress.data.code == 200){
						let _addressDefault = defaultAddress.data.data;
						if(_addressDefault){
						    this.addressDefault = _addressDefault;
						    /*查询运费*/
							this.qLogistics()
						}
						uni.hideLoading();
					}
                    
				}else if(this.orderStatus=="detailPay"||this.orderStatus=="pending"||this.orderStatus=="comment" || this.orderStatus=="refund" ||this.orderStatus=='finish'){
					this.addressDefault = {
                        // defaultStatus: 0,
						province: this.dataString.receiverProvince,
						city: this.dataString.receiverCity,
                        region: this.dataString.receiverRegion,
                        detailAddress: this.dataString.receiverDetailAddress,
                        // id: 83,
                        idCard: this.dataString.receiverIdcard,
                        // memberId: 66,
                        name: this.dataString.receiverName,
                        phoneNumber: this.dataString.receiverPhone
                    }
				}
				uni.hideLoading();
				console.log(this.detailList,33333);
            },
			//显示优惠券面板
			toggleMask(type){
                if(this.orderStatus!=="create"){
                    return false
				}
				let timer = type === 'show' ? 10 : 300;
				let	state = type === 'show' ? 1 : 0;
				this.maskState = 2;
				setTimeout(()=>{
					this.maskState = state;
				}, timer)
			},
			/*使用优惠券*/
			useCoupon(item){
			    if(item=="no"){
                    this.useCouponObj={
                        coupon:{
                            amount:0
						}
					}

				}else{
			        if(item.coupon.type==0 || item.coupon.type==2){
                        this.useCouponObj = item;
					}else if(item.coupon.type==1){
                        this.useCouponObj = item;
                        let discountRatio = item.coupon.discountRatio/10;
                        let discountCeiling = item.coupon.discountCeiling;

                        let discount = (this.dataSobj.buyTotal*(1-discountRatio)).toFixed(2);
						if(!this.dataString){
						    discount = (((this.detailList[0].omsCartItems[0].price) * this.buyNum)*(1-discountRatio)).toFixed(2)
						}
                        if(discount>discountCeiling){
                            discount = discountCeiling
						}
                        this.useCouponObj.coupon.amount=discount;
					};

				}

			    this.toggleMask()
			},
			numberChange(data) {
				this.number = data.number;
			},
			changePayType(type){
				this.payType = type;
			},
			async submit(n){
			    if(n=="create"){
                    /*创建订单*/
					if(!this.addressDefault){
					    this.$api.msg("请选择需要收货的地址哦");
						return false;
					}
                    let para = null;
                    if(this.dataString){
                        //购物车
                        para = {
                            addressId:this.addressDefault.id.toString(),//收货地址id(必须)
//                        couponId:"",//优惠券Id(必须)
                            type:"2",//("选择类型 1，商品详情 2 勾选购物车 3全部购物车的商品")（必须）,
                            freight:this.LSTS=="免运费"?0:this.LSTS,//("运费")（必须）
                            couponFee:"",//("优惠费用")（可传）,
                            totalPrice:this.dataSobj.buyTotal,//("合计价格")（可传,
                            cartIds:(this.dataSobj.carIds).substr(0,this.dataSobj.carIds.length - 1),//("购物车id")("购物车id的字符串拼接")(勾选购物车中的商品的购物车id拼接，逗号拼接）
                        };
                        //               /*判断抢购是否结束*/
                            let pStatic = false;/*抢购结束状态默认值*/

                            console.log("!11111111111111111111");
                            this.dataString.forEach((itemF)=>{
                                let tempPanic = itemF.omsCartItems;
                                tempPanic.forEach((item)=>{
                                    if(item.flashEndTime){
                                        if(item.flashStatus=="end"){
                                            pStatic = true;
//                            throw new Error("break")
                                        }
                                    }
                                });
                            })
                            if(pStatic){
                                uni.showModal({
                                    title: '提示',
                                    content: '当前订单中的商品抢购已结束',
                                    showCancel:false,
                                    confirmText:"确定",
                                    confirmColor:"#017F01",
                                    success: function (res) {
                                        if (res.confirm) {

                                        } else if (res.cancel) {

                                        }
                                    }
                                });
                                return false;
                            }
                    }else{
                        //正常
                         para = {
                            addressId:this.addressDefault.id.toString(),//收货地址id(必须)
//                        couponId:"",//优惠券Id(必须)
                            type:"1",//("选择类型 1，商品详情 2 勾选购物车 3全部购物车的商品")（必须）,
                            freight:this.LSTS=="免运费"?0:this.LSTS,//("运费")（必须）
                            count:parseInt(this.buyNum),//("商品详情到支付时的商品数量")（必传）

                            couponFee:"",//("优惠费用")（可传）,
                            totalPrice:((this.detailList[0].omsCartItems[0].price) * this.buyNum).toString(),//("合计价格")（可传,
//                        useIntegration:"",//使用的积分数
//                        payType:"",//到支付时传递的，生成订单不必传
                            cartId:this.detailList[0].omsCartItems[0].id,//("购物车id")（商品详情到立即付款生成订单时传递的参数，调用api/cart/bookOrder返回的id）
//                        cartIds:"",//("购物车id")("购物车id的字符串拼接")(勾选购物车中的商品的购物车id拼接，逗号拼接）
//                        flashRelationId:"",//("flashRelationId为商品限时购与商品关系表的id")（限时商品传递，正常商品不需要传）
//                        verifyStatus:""//("积分兑换商品,0不是，1是")（积分兑换商品必须传，其余不必）

                        };
                        if(this.bStatus=="panic"){
                            para.flashRelationId = this.fId;
                            //               /*判断抢购是否结束*/
                            let pStatic = false;/*抢购结束状态默认值*/

                            console.log("!11111111111111111111");
                            this.detailList.forEach((itemF)=>{
                                let tempPanic = itemF.omsCartItems;
                                tempPanic.forEach((item)=>{
                                    if(item.flashEndTime){
                                        if(item.flashStatus=="end"){
                                            pStatic = true;
//                            throw new Error("break")
                                        }
                                    }
                                });
                            })
                            if(pStatic){
                                uni.showModal({
                                    title: '提示',
                                    content: '当前订单中的商品抢购已结束',
                                    showCancel:false,
                                    confirmText:"确定",
                                    confirmColor:"#017F01",
                                    success: function (res) {
                                        if (res.confirm) {

                                        } else if (res.cancel) {

                                        }
                                    }
                                });
                                return false;
                            }
                        }

                    }
					console.log(this.useCouponObj.id)
                    if(this.useCouponObj.id){
                        console.log(this.useCouponObj);
                        para.couponId = this.useCouponObj.coupon.id
                    }else{
                        delete para.couponId
					}
                    let tempBuy = await _buyCart(para);
                    let data = tempBuy.data;
                    if(data.code==200){
                        //去支付
						if(data.data == '请先完成账户信息填写真实姓名身份证'){
							this.$api.msg(`请先完成账户信息填写真实姓名身份证`);
							setTimeout(()=>{
								uni.navigateTo({
									url: `/pages/user/verified`
								})
							}, 2100)
						}else{
							if(this.bStatus=="integral"){
							    uni.navigateTo({
							        url: '/pages/money/pay?orderId='+data.data.order.id+'&t='+((this.detailList[0].omsCartItems[0].integralNum) * this.buyNum).toString()+'&payStatus=integral'
							    })
							}else{
							    uni.navigateTo({
							        url: '/pages/money/pay?orderId='+data.data.order.id+'&t='
										+(para.totalPrice-this.useCouponObj.coupon.amount
											+parseInt(this.LSTS==='免运费'?0:this.LSTS)
									).toFixed(2)
							    })
							}
						}
                    }
                    // console.log(para)
				}else if(n=="pay"){
			        /*待付款，去付款*/
                    if(this.bStatus=="integral"){
                        uni.navigateTo({
                            url: '/pages/money/pay?orderId='+this.dataString.id+'&t='+((this.detailList[0].omsCartItems[0].integral) * (this.detailList[0].omsCartItems[0].quantity)).toString()+'&payStatus=integral'
                        })
                    }else{
                        //               /*判断抢购是否结束*/
                        let pStatic = false;/*抢购结束状态默认值*/
                        let tempPanic = this.dataString.orderItemList;
                        console.log("!11111111111111111111");
                        tempPanic.forEach((item)=>{
                            if(item.flashEndTime){
                                if(item.flashStatus=="end"){
                                    pStatic = true;
//                            throw new Error("break")
                                }
                            }
                        });
                        if(pStatic){
                            uni.showModal({
                                title: '提示',
                                content: '当前订单中的商品抢购已结束',
                                showCancel:false,
                                confirmText:"确定",
                                confirmColor:"#017F01",
                                success: function (res) {
                                    if (res.confirm) {

                                    } else if (res.cancel) {

                                    }
                                }
                            });
                            return false;
                        }
                        uni.navigateTo({
                            url: '/pages/money/pay?orderId='+this.dataString.id+'&t='+this.dataSobj.buyTotalTrue
                        })
                    }

				}else if(n=="cancel"){
				    /*代付款，取消付款*/
				}else if(n=="wuliu"){
				    /*去物流*/
                    uni.navigateTo({
                        url: `/pages/logistics/logistics?orderId=${this.dataString.id}&count=${this.dataString.allCount}&pic=${this.dataString.orderItemList[0].productPic}`
                    })
				}else if(n=="receive"){
				    /*确认收货*/
				}else if(n=="appraise"){
				    /*评价货物*/
                    uni.navigateTo({
                        url: `/pages/appraise/release?orderId=${this.dataString.id}`
                    })
				}
			},
			/*获取商品优惠券*/
			async gotCoupon(para){
			    let tempData = await _userCoupon(para);
				if(tempData.data.code == 200){
					this.couponList = tempData.data.data;
					this.couponList.forEach((item=>{
					    item.endTime = util.formatDate.format(new Date(item.endTime),'yyyy-MM-dd')
					}))
					uni.hideLoading();
				}	
			},
            /*确认收货*/
            async conifrmPro(orderId){
                if(this.dataString.isHaveRefund && this.dataString.isHaveRefund==1){
                    uni.showModal({
                        title: '提示',
                        content: '当前订单有正在退款的商品，取消退款后才能确认收货哦',
                        showCancel:false,
                        confirmText:"知道啦",
                        confirmColor:"#017F01",
                        success: function (res) {
                            if (res.confirm) {

                            } else if (res.cancel) {

                            }
                        }
                    });
                    return false;
				}
                let tempData = await _confirmPro({id:orderId});
                /*成功后跳转评价页面*/
                if(tempData.data.code==200){
                    this.$api.msg("确认收货成功！");
                    setTimeout(function () {
                        uni.navigateTo({
                            url: `/pages/appraise/release?orderId=${orderId}`
                        })
                    },1000)
//                    setTimeout(function () {
//                        uni.switchTab({
//                            url: '/pages/index/index'
//                        });
//                    },1000)
                }
            },
			/*退款*/
			async goRefund(orderId,cItem){
                uni.navigateTo({
                    url: `/pages/refund/refund?orderId=${orderId}&data=${JSON.stringify(cItem)}`
				})
			},
			/*退款详情*/
			async goRefundDetail(orderId,proId,productSkuId){
    //             uni.navigateTo({
    //                 url: `/pages/refund/refund_detail?orderId=${orderId}&proId=${proId}&productSkuId=${productSkuId}`
				// })
			},
			goAddress(){
			    if(this.orderStatus=="create"){
                    uni.navigateTo({
                        url:"/pages/address/address?source=1"
                    })
				}
			},
			/*获取各种状态的订单详情*/
            async getOrdDetail(){
              let para = {id:this.getOrderId};
              let tempData = await _orderDetail(para)
				console.log(tempData.data.data,1515)
			},
			/*运费*/
			async qLogistics(){
                console.log(this.detailList)
				if(this.detailList.length==0){
                    setTimeout((item)=>{
                        this.qLogistics()
					},500)
				}else{
                    let _addressDefault = this.addressDefault.detailAddress;
                    let cartIds=null;
                    if(this.cartIds){
                        cartIds = this.cartIds
					}else{
                        cartIds = [];
                        this.detailList[0].omsCartItems.forEach(item=>{
                                cartIds.push(item.id)
						});
                        cartIds = cartIds.toString()
					}
                    let logPara = {
                        // id:this.id?this.id:this.detailList[0].omsCartItems[0].productId,
                        cartIds:cartIds,
                        province:this.addressDefault.province,
                        city:this.addressDefault.city,
                    };

                    let logTempData = await _gLogistics(logPara);
                    console.log("运费："+logTempData);
                    if(logTempData.data.data){
                        this.LSTS = logTempData.data.data.freight==0?'免运费':logTempData.data.data.freight
                    }
				}


			},
			stopPrevent(){}
		}
	}
</script>

<style lang="scss">
	page {
		background: $page-color-base;
		padding-bottom: 160upx;
	}

	.address-section {
		padding: 30upx 0;
		background: #fff;
		position: relative;

		.order-content {
			display: flex;
			align-items: center;
		}
        .isNo{
            padding-left: 40upx;
        }
		.icon-shouhuodizhi {
			flex-shrink: 0;
			display: flex;
			align-items: center;
			justify-content: center;
			width: 90upx;
			color: #888;
			font-size: 44upx;
		}

		.cen {
			display: flex;
			flex-direction: column;
			flex: 1;
			font-size: 26upx;
			color: $font-color-dark;
            .tag{
                font-size: 24upx;
                color: $uni-color-primary;
                margin-right: 10upx;
                background: #EEF4EE;
                /*border: 1px solid #ffb4c7;*/
                border-radius: 4upx;
                padding: 4upx 10upx;
                line-height: 1;
                margin-left: 30upx;
            }
		}

		.name {
			/*font-size: 34upx;*/
			margin-right: 28upx;
		}
		.mobile{
			font-size: 24upx;
		}
		.address {
			margin-top: 24upx;
			margin-right: 20upx;
			color: $font-color-light;
		}

		.icon-you {
			font-size: 32upx;
			color: $font-color-light;
			margin-right: 30upx;
		}

		.a-bg {
			position: absolute;
			left: 0;
			bottom: 0;
			display: block;
			width: 100%;
			height: 5upx;
		}
	}

	.goods-section {
		margin-top: 16upx;
		background: #fff;
		padding-bottom: 1px;

		.g-header {
			display: flex;
			align-items: center;
			height: 84upx;
			padding: 0 30upx;
			position: relative;
			.name {
				font-size: 32upx;
				color: $font-color-dark;
				/*margin-left: 24upx;*/
				font-weight: bold;
			}
			.g-status{
				color: $uni-color-primary;
				font-size: 30upx;
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: flex-end;
			}
		}
		.g-item {
			display: flex;
			margin: 20upx 30upx;
			border-bottom: 2upx solid #f2f2f2;
			padding-bottom: 20upx;
            flex-wrap: wrap;
			image {
				flex-shrink: 0;
				display: block;
				width: 140upx;
				height: 140upx;
				border-radius: 4upx;
			}

			.right {
				flex: 1;
				padding-left: 24upx;
				overflow: hidden;
				.refund{
					display: flex;
					font-size: 22upx;
					color: #989898;
					/*<!--margin-top: -40rpx;-->*/
					justify-content: flex-end;
					button{
						border: none;
						outline: none;
						width: 100%;
						padding: 0;
						/*line-height: 40upx;*/
						height: 100%;
						background: #ffffff;
						display: flex;
						line-height: 40rpx;
						text-align: left;
						font-size: 22upx;
						color: #989898;
						/*<!--margin-top: -40rpx;-->*/
						justify-content: flex-end;
					}
					button::after{
						border: none;
					}
					text{
						border: 2upx solid #989898;
						border-radius: 60upx;
						padding: 10upx 30upx;
						color: #282828;
					}
				}
			}

			.title {
				font-size: 28upx;
				color: $font-color-dark;
				padding-top: 10rpx;
                .t-name{
                    width: 376upx;
                    overflow: hidden;
                    white-space: nowrap;
                    text-overflow: ellipsis;
                }
                .price{
                    font-size: 26upx;
                    color: #656565;
                    float: right;
                    margin-top: -38rpx;
                }
			}

			.spec {
				font-size: 24upx;
				color: $font-color-light;
			}

			.price-box {
				/*display: flex;*/
				align-items: center;
				font-size: 24upx;
				color: #989898;
				padding-top: 10upx;
				view{
					display: flex;
					align-items: center;
				}
				.price {
					margin-bottom: 4upx;
				}
				.number{
					font-size: 26upx;
					color: $font-color-base;
					margin-left: 20upx;
                    float: right;
                    margin-top: -34rpx;
                }
                img{
                    width: 23upx;
                    height: 23upx;
                    display: inline-block;
                    margin-right: 20upx;
					border-radius: 50%;
                }
			}

			.step-box {
				position: relative;
			}
		}
	}
	.yt-list {
		margin-top: 16upx;
		background: #fff;
	}

	.yt-list-cell {
		display: flex;
		align-items: center;
		padding: 10upx 30upx 10upx 40upx;
		line-height: 70upx;
		position: relative;

		&.cell-hover {
			background: #fafafa;
		}

		&.b-b:after {
			left: 30upx;
		}

		.cell-icon {
			height: 32upx;
			width: 32upx;
			font-size: 22upx;
			color: #fff;
			text-align: center;
			line-height: 32upx;
			background: #f85e52;
			border-radius: 4upx;
			margin-right: 12upx;

			&.hb {
				background: #ffaa0e;
			}

			&.lpk {
				background: #3ab54a;
			}

		}

		.cell-more {
			align-self: center;
			font-size: 24upx;
			color: $font-color-light;
			margin-left: 8upx;
			margin-right: -10upx;
		}

		.cell-tit {
			flex: 1;
			font-size: 26upx;
			color: $font-color-dark;
			margin-right: 10upx;
		}

		.cell-tip {
			font-size: 26upx;
			color: $font-color-dark;

			&.disabled {
				color: $font-color-light;
			}

			&.active {
				color: $base-color;
			}
			&.red{
				color: $base-color;
			}
		}

		&.desc-cell {
			.cell-tit {
				max-width: 90upx;
			}
		}
		&.actually{
			.m{
				font-size: 30upx;
				color: $uni-color-primary;
			}
		}
		.desc {
			flex: 1;
			font-size: $font-base;
			color: $font-color-dark;
		}
	}
	
	/* 支付列表 */
	.pay-list{
		padding-left: 40upx;
		margin-top: 16upx;
		background: #fff;
		.pay-item{
			display: flex;
			align-items: center;
			padding-right: 20upx;
			line-height: 1;
			height: 110upx;	
			position: relative;
		}
		.icon-weixinzhifu{
			width: 80upx;
			font-size: 40upx;
			color: #6BCC03;
		}
		.icon-alipay{
			width: 80upx;
			font-size: 40upx;
			color: #06B4FD;
		}
		.icon-xuanzhong2{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 60upx;
			height: 60upx;
			font-size: 40upx;
			color: $base-color;
		}
		.tit{
			font-size: 32upx;
			color: $font-color-dark;
			flex: 1;
		}
	}
	/*底部*/
	.footer{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 995;
		display: flex;
		align-items: center;
		width: 100%;
		height: 100upx;
		justify-content: space-between;
		font-size: 30upx;
		background-color: #fff;
		z-index: 998;
		color: $font-color-base;
		box-shadow: 0 -1px 5px rgba(0,0,0,.1);
		.price-content{
			padding-left: 30upx;
		}
		.price-tip{
			color: $uni-color-primary;
			margin-left: 8upx;
		}
		.price{
            font-size: 30upx;
            font-weight: 500;
            color: $uni-color-primary;
		}
		.submit{
			display:flex;
			align-items:center;
			justify-content: center;
			color: #fff;
			font-size: 32upx;
            border-radius: 100upx;
			background-color: $uni-color-primary;
            padding: 22rpx 36rpx;
            margin-right: 30rpx;

        }
        .total{
            color: #989898;
            font-size: 20upx;
        }
	}
	.footer.detail{
		justify-content: flex-end;
		.submit{
			font-size: 26upx;
		}
		.cancel{
			color: #989898;
			border: 2upx solid #989898;
			background: #ffffff;
		}
		.pay{
			color: $uni-color-primary;
			border: 2upx solid $uni-color-primary;
			background: #ffffff;
		}
	}
	
	/* 优惠券面板 */
	.mask{
		display: flex;
		align-items: flex-end;
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0,0,0,0);
		z-index: 9995;
		transition: .3s;
		
		.mask-content{
			width: 100%;
			min-height: 30vh;
			max-height: 70vh;
			background: #f3f3f3;
			transform: translateY(100%);
			transition: .3s;
			overflow-y:scroll;
		}
		&.none{
			display: none;
		}
		&.show{
			background: rgba(0,0,0,.4);
			
			.mask-content{
				transform: translateY(0);
			}
		}
	}

	/* 优惠券列表 */
	.coupon-item{
		display: flex;
		flex-direction: column;
		margin: 20upx 24upx;
		background: #fff;
		.con{
			display: flex;
			align-items: center;
			position: relative;
			min-height: 120upx;
			padding: 0 30upx;
			&:after{
				position: absolute;
				left: 0;
				bottom: 0;
				content: '';
				width: 100%;
				height: 0;
				border-bottom: 1px dashed #f3f3f3;
				transform: scaleY(50%);
			}
		}
		.left{
			display: flex;
			flex-direction: column;
			justify-content: center;
			flex: 1;
			overflow: hidden;
			// height: 100upx;
			padding: 20rpx 0;
		}
		.title{
			font-size: 32upx;
			color: $font-color-dark;
			margin-bottom: 10upx;
		}
		.time{
			font-size: 24upx;
			color: $font-color-light;
		}
		.right{
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 26upx;
			color: $font-color-base;
			height: 100upx;
		}
		.price{
			font-size: 44upx;
			color: $uni-color-primary;
			&:before{
				content: '￥';
				font-size: 34upx;
			}
		}
		.tips{
			font-size: 24upx;
			color: $font-color-light;
			line-height: 60upx;
			padding-left: 30upx;
		}
		.circle{
			position: absolute;
			left: -6upx;
			bottom: -10upx;
			z-index: 10;
			width: 20upx;
			height: 20upx;
			background: #f3f3f3;
			border-radius: 100px;
			&.r{
				left: auto;
				right: -6upx;
			}
		}
		.other{
			font-size: 32upx;
			text-align: center;
			padding: 30upx 0;
		}
	}
	.panic{
		font-size: $font-sm - 2upx;
        padding: 20rpx 0 30rpx 10rpx;
        width: 100%;
        .tag{
			color: $uni-color-primary;
			border: 2upx solid $uni-color-primary;
			padding: 5upx 10upx;
			border-radius: 50upx;
		}
		text{
			margin-right: 10upx;
		}
	}
	.disabled{
		.panic{
			color: #DADADA;
			.tag{
				color: #DADADA;
				border: 2upx solid #DADADA;
			}
		}
		.cart-item{
			.item-right{
				.title,.price,.attr,.unit{
					color: #DADADA;
				}
				.unit{
					text{
						color: #DADADA;
					}
				}
			}
		}

	}
</style>
